﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

using WFNetLib.GDI;

namespace PassportManage
{
    public partial class Form_Main : Form
    {
        //public static string UserName;
        public Form form;
        //private bool ComListening = false;//是否没有执行完invoke相关操作
        //private bool ComClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke
       // public BLL.PassportSerialPort PS485;        
        public Form_Main()
        {
            InitializeComponent();
        }
        public Form_Main(string adminname,Form f)
        {
            InitializeComponent();
            this.CenterToParent();
            Common.AppInfo.Operator = adminname;
            form = f;

            //this.FormBorderStyle = FormBorderStyle.None;
            //WindowState = FormWindowState.Maximized;

            //Rectangle rect = SystemInformation.VirtualScreen;
            //Bitmap bt = new Bitmap(rect.Width, rect.Height);
            //ImageFillRect.Image_FillRect(new Bitmap(this.BackgroundImage), bt, FillMode.Struk);
            //this.BackgroundImage = bt;
            //bt.Dispose();            
            //Update();
            BLL.GetPassportPosition.InitPillarState();
            WFNetLib.Log.SystemLogData.DefaultOperator = Common.AppInfo.Operator;
            WFNetLib.Log.SystemLogData log = new WFNetLib.Log.SystemLogData();
            log.LogType = Common.LogType.用户相关.ToString();
            log.LogContent = Common.AppInfo.Operator;
            log.LogRemark = "登陆";
            log.InserSQLLog();
            slOperator.Text = Common.AppInfo.Operator;
        }       
        private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime date = DateTime.Now;
            string str = string.Format("往前时间：{0}年{1}月{2}日  {3}:{4}:{5}", date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
            slTime.Text = str;
        }
        private void Form_main_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 9)
            {
                List<PictureBox> piclist = new List<PictureBox>();
                piclist.Add(this.SavePassport);                
                piclist.Add(this.TakeOutPassport);
                piclist.Add(this.pictureBox5);
                piclist.Add(this.pictureBox6);
            }
        }
        private void Form_main_FormClosing(object sender, FormClosingEventArgs e)
        {
            form.Close();
        }

        private void pictureBox12_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要退去本系统吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                this.Close();
        }

        private void SaveSingle_Click(object sender, EventArgs e)
        {            
            Form_Save f = new Form_Save();
            f.ShowDialog();
        }
        private void pictureBox2_Click(object sender, EventArgs e)
        {            
            
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            
        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            
            Form_Setting f = new Form_Setting();
            f.ShowDialog();
        }

        private void Form_Main_Load(object sender, EventArgs e)
        {
//             PS485 = new BLL.PassportSerialPort();
//             if (PS485.OpenSerialPort() == Common.RS485Result.Close)
//                 MessageBox.Show("护照数据通信端口打开失败，无法进行护照的存入和取出记录工作！");
        }
        protected override void OnClosed(System.EventArgs e)
        {
            //PS485.ReleaseSerialPort();
            //OnClosed(e);
        }

        private void TakeOutPassport_Click(object sender, EventArgs e)
        {
            
            Form_TakeOut f = new Form_TakeOut();
            f.ShowDialog();
        }

        private void SystemLog_Click(object sender, EventArgs e)
        {
            /*Form_SystemLog f = new Form_SystemLog();*/
            WFNetLib.Log.Form_LogShow_Normal f = new WFNetLib.Log.Form_LogShow_Normal(Enum.GetNames(typeof(Common.LogType)), true);
            //WFNetLib.Log.Form_LogShow_AllConditon f = new WFNetLib.Log.Form_LogShow_AllConditon(true);
            f.ShowDialog();
        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox11_Click(object sender, EventArgs e)
        {
            Form_Statistics f = new Form_Statistics();
            f.ShowDialog();
        }        
    }
}
